package com.tanhua.server.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tanhua.server.mapper.UserInfoMapper;
import com.tanhua.server.pojo.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author Au
 * @DATE 2020/11/16 22:39
 **/
@Service
public class UserInfoService {

    @Autowired
    private UserInfoMapper userInfoMapper;


    /**
     * 查询数据库,查找用户的信息数据
     *
     * @param id
     * @return
     */
    public UserInfo queryUserInfoById(Long id) {
        UserInfo userInfo = userInfoMapper.selectById(id);
        return userInfo;
    }

    /**
     * 查询用户列表信息
     * @param queryWrapper
     * @return
     */
    public List<UserInfo> queryUserInfoList(QueryWrapper queryWrapper) {
        return userInfoMapper.selectList(queryWrapper);
    }


    public boolean updateUserInfoByUserId(UserInfo userInfo) {
        QueryWrapper<UserInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", userInfo.getUserId());
        return this.userInfoMapper.update(userInfo, queryWrapper) > 0;
    }
}
